package com.elastic.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.elastic.bean.Hotel;
import com.elastic.dao.HotelDao;
import com.elastic.param.QueryHotelParam;
import com.elastic.param.UpdateHotelParam;
import com.elastic.service.IHotelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class HotelServiceImpl extends ServiceImpl<HotelDao,Hotel> implements IHotelService {

    @Autowired
    private HotelDao hotelDao;

    @Override
    public Hotel getById(Long id) {
        return hotelDao.selectById(id);
    }

    @Override
    public List<Hotel> getByIds(List<Long> ids) {
        List<Hotel> hotels = hotelDao.selectBatchIds(ids);
        return hotels;
    }

    @Override
    public boolean deleteByIds(List<Long> ids) {

        return removeBatchByIds(ids,2);
    }

    @Override
    public Page<Hotel> getPage(QueryHotelParam param) {

        Page<Hotel> page = new Page<>(param.getPageNo(),param.getPageSize());


//       PageHelper.startPage(param.getPageNo(), param.getPageSize());


        LambdaQueryWrapper<Hotel> query = new LambdaQueryWrapper<>();

        query.eq(Hotel::getPic,param.getPic());



        return hotelDao.selectPage(page,query);
    }

    @Override
    public boolean updateByIds(List<UpdateHotelParam> params) {
        List<Hotel> hotels = new ArrayList<>();

        for (UpdateHotelParam param : params) {
            Hotel hotel = new Hotel();
            hotel.setId(param.getId());
            hotel.setPic(param.getPic());
            hotel.setPrice(param.getPrice());
            hotels.add(hotel);
        }
        return updateBatchById(hotels);
    }


}
